package json.val;

import json.Util;

import java.util.ArrayList;

public class ArrayVal extends JsonVal {
    ArrayList<JsonVal> valueList;

    public ArrayVal() {
        valueList = new ArrayList<>();
    }
    public ArrayVal(ArrayList<JsonVal> valueList) {
        this.valueList = valueList;
    }

    public void addValue(String val){
        StringVal stringVal = new StringVal(val);
        valueList.add(stringVal);
    }
    public void addValue(JsonVal val){
        valueList.add(val);
    }

    public ArrayList<JsonVal> getValueList() {
        return valueList;
    }

    @Override
    public String serializeSelf(int tabNum) {
        StringBuilder sb = new StringBuilder();
        sb.append("[\n");
        boolean isFirst = true;
        for (JsonVal jsonVal : valueList) {
            if (isFirst){
                isFirst = false;
            }
            else {
                sb.append(",\n");
            }
            Util.printTab(tabNum, sb);
            sb.append(jsonVal.serializeSelf(tabNum+1));
        }
        sb.append('\n');
        Util.printTab(tabNum-1, sb);
        sb.append(']');
        return sb.toString();
    }

    @Override
    public String toString() {
        return valueList.toString();
    }
}
